<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/5/15 0015
 * Time: 19:56
 */

namespace App\Socket\Packets;


use App\Socket\Models\Protocol;

class HeartBeatPacket
{
    /**
     * @var HeartBeatPacket
     */
    private static $instance;

    /**
     * @return HeartBeatPacket
     */
    public static function instance()
    {
        if (self::$instance == null) {
            self::$instance = new self();
        }
        return self::$instance;
    }

    /**
     * 心跳包回执
     * @param $data
     * @return Protocol
     */
    public function handle($data)
    {
        return Protocol::toObject([
            'ack'   => 1,
            'cid'   => $data['cid'] ?? Protocol::makeCid(),
            'code'  => Protocol::CODE_HEARTBEAT
        ]);
    }
}